<template>
  <div class="login-container">
    <div class="login-box">
      <div class="title-container">
        <h3 class="title">汽车租赁管理系统</h3>
      </div>
      
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
        <el-form-item prop="username">
          <el-input
            v-model="loginForm.username"
            prefix-icon="el-icon-user"
            placeholder="请输入用户名"
            clearable
          />
        </el-form-item>
        
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            prefix-icon="el-icon-lock"
            :type="passwordVisible ? 'text' : 'password'"
            placeholder="请输入密码"
            @keyup.enter.native="handleLogin"
          >
            <i
              slot="suffix"
              :class="passwordVisible ? 'el-icon-view' : 'el-icon-hide'"
              @click="passwordVisible = !passwordVisible"
            />
          </el-input>
        </el-form-item>
        
        <el-form-item>
          <el-button
            :loading="loading"
            type="primary"
            class="login-button"
            @click.native.prevent="handleLogin"
          >登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: 'admin',
        password: '123456'
      },
      loginRules: {
        username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      },
      passwordVisible: false,
      loading: false
    }
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store
            .dispatch('login', this.loginForm)
            .then(() => {
              this.$message.success('登录成功')
              this.$router.push('/home')
              this.loading = false
            })
            .catch(error => {
              this.$message.error(error || '登录失败，请重试')
              this.loading = false
            })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  overflow: hidden;
  
  .login-box {
    width: 90%;
    max-width: 400px;
    padding: 40px 35px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 15px 25px rgba(0, 0, 0, 0.1);
    
    .title-container {
      margin-bottom: 30px;
      text-align: center;
      
      .title {
        font-size: 24px;
        color: #303133;
        font-weight: 500;
      }
    }
    
    .login-form {
      .el-input {
        height: 48px;
      }
      
      ::v-deep .el-input__inner {
        height: 48px;
        line-height: 48px;
        border-radius: 4px;
        padding-left: 44px;
        background-color: #f5f7fa;
        border: 1px solid #e4e7ed;
        
        &:focus {
          border-color: #409eff;
          background-color: #fff;
        }
      }
      
      ::v-deep .el-input__prefix {
        left: 10px;
        line-height: 48px;
        color: #909399;
      }
      
      .login-button {
        width: 100%;
        height: 48px;
        border-radius: 4px;
        margin-top: 10px;
        font-size: 16px;
      }
    }
  }
}

/* 响应式调整 */
@media screen and (max-width: 768px) {
  .login-container {
    .login-box {
      padding: 30px 20px;
    }
  }
}
</style> 